<?php
declare (strict_types = 1);

namespace app\command;

use app\service\Keyword;
use app\model\admin\Keyword AS model;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;


class RunData extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('rundata')
            ->setDescription('the rundata command');
    }

    protected function execute(Input $input, Output $output)
    {
        $i = $j = 1;
        // 指令输出
        while (true) {
            $generateRandomString = $this->generateRandomString(20);
            $output->writeln($i.uniqid().rand(0,99999999).$generateRandomString.'----'.'NUMBER:'.$i.(rand(10,99)).($i + 2).'---进度('.$j.'%)');
            $j++;
            if ($j > 100)
                $j = 1;
            $i++;
            if ($i > 10000000000000){
                break;
            }
            usleep(rand(1,20000));
        }
//        $keyword = new Keyword();
//        $select = model::where('is_update',1)->select();
//        foreach ($select AS $key => $value){
//            $output->writeln('进度:('.($key + 1).'/.'.count($select).')');
//            $output->writeln('关键词:('.$value->keyword.')===>更新结果:'.$keyword->save($value->keyword));
//            $output->writeln('PC:'.$value->pc.' PHONE:'.$value->phone.' ALL:'.$value->all);
//            $output->writeln('PCPRICE:'.$value->pc_price.' PHONE_PRICE:'.$value->phone_price.' ALL_PRICE:'.$value->price);
//            $output->writeln('相关长尾词:'.$value->keywords);
//            usleep(500);
//        }
    }
    private function generateRandomString($length) {
        $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
}
